//
//  XVisitorView.swift
//  WeiBoReDo
//
//  Created by 放学跟鸽走 on 2017/4/8.
//  Copyright © 2017年 放学跟鸽走. All rights reserved.
//

import UIKit
import SnapKit
class XVisitorView: UIView {
    
    //注册按钮
    lazy var registBtn:UIButton = UIButton.cz_textButton("注册", fontSize: 16, normalColor: UIColor.orange, highlightedColor: UIColor.black , backgroundImageName: "common_button_white_disable")
    //登录按钮
    lazy var loginBtn:UIButton = UIButton.cz_textButton("登录", fontSize: 16, normalColor: UIColor.gray, highlightedColor: UIColor.orange , backgroundImageName: "common_button_white_disable")
    
    //图像
    fileprivate lazy var iconImg:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_smallicon"))
    fileprivate lazy var iconMaskImg:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_mask_smallicon"))
    //房子
    fileprivate lazy var houseImg:UIImageView = UIImageView(image: UIImage(named: "visitordiscover_feed_image_house"))
    //提示标签
    fileprivate lazy var tipLabel:UILabel = UILabel.cz_label(withText: "关注一些人，再回到这里，你会得到许多惊喜你会得到许多惊喜", fontSize: 16, color: UIColor.gray)
    
    
    var visitorInfo:[String:String]?{
        didSet{
            guard let imageName = visitorInfo?["imageName"],
                let message = visitorInfo?["message"]
                else {
                    return
            }
            tipLabel.text = message
            if imageName == ""{
                startAnimate()
                return
            }
            iconImg.image = UIImage(named: imageName)
            houseImg.isHidden = true
            iconMaskImg.isHidden = true
            
            
        }
    }
    func startAnimate(){
        let anim = CABasicAnimation(keyPath: "transform.rotation")
        anim.duration = 15
        anim.fromValue = -2*Double.pi
        anim.toValue = 0
        anim.repeatCount = MAXFLOAT
        anim.isRemovedOnCompletion = false
        iconImg.layer.add(anim, forKey: nil)
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        setupUI()
    }
    
}

// MARK: - UI搭建
extension XVisitorView{
    func setupUI(){
         backgroundColor = UIColor.cz_color(withHex: 0xEDEDED)
        print(#function)
        addSubview(iconImg)
        addSubview(iconMaskImg)
        addSubview(houseImg)
        addSubview(tipLabel)
        addSubview(registBtn)
        addSubview(loginBtn)
        //一圈的小图标
        iconImg.snp.makeConstraints { (make) in
            make.center.equalTo(snp.center)
        }
        houseImg.snp.makeConstraints { (make) in
            make.center.equalTo(iconImg.snp.center)
        }
        tipLabel.snp.makeConstraints { (make) in
            make.centerX.equalTo(snp.centerX)
            make.top.equalTo(iconImg.snp.bottom).offset(20)
            make.width.equalTo(236)
        }
        iconMaskImg.snp.makeConstraints { (make) in
            make.top.equalTo(snp.top)
            make.left.equalTo(snp.left)
            make.right.equalTo(snp.right)
            make.bottom.equalTo(loginBtn.snp.top)
            
        }
        loginBtn.snp.makeConstraints { (make) in
            make.top.equalTo(tipLabel.snp.bottom)
            make.right.equalTo(tipLabel.snp.right)
            make.width.equalTo(100)
            make.height.equalTo(36)
            
        }
        registBtn.snp.makeConstraints { (make) in
            make.left.equalTo(tipLabel.snp.left)
            make.top.equalTo(tipLabel.snp.bottom)
            make.size.equalTo(loginBtn.snp.size)
        }
        
    }
}
